/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package src.services.loan;

import java.math.BigDecimal;
import java.util.List;
import java.util.Map;
import javax.faces.model.SelectItem;
import src.domain.loan.Marketing;
import src.services.CRUEDService;
import src.util.Utils;

/**
 *
 * @author Yusup Jauhari Shandi <in.visi>
 */
public class MarketingModel implements java.io.Serializable{
    private CRUEDService service;
    
    public MarketingModel() {
        service = new CRUEDService();
    }
    
    public List<Marketing> findAll(Map<String, String> filters) {
        return (List<Marketing>) service.findAll("Marketing", filters);
    }
   
    public Map<Integer, String> mapAll() {
        return service.mapAll("Marketing", "marketingId", "marketingName");
    }
    
    public List<SelectItem> listAll() {
        return service.listAll("Marketing", "marketingId", "marketingName");
    }
    
    public Marketing getById(Integer id) {
        return (Marketing)  service.getById(Marketing.class, id);
    }
    
    public boolean isMarketingExist(String value, Integer id) {
        BigDecimal count;
        String cond = " where marketing_name = "+Utils.fmtSQLString(value);
        if (id != null) cond+=" and marketing_id <> "+id;
        
        try { count = (BigDecimal) service.getObjectSQLdirect("select count(*) from Marketing "+cond);
        } catch (RuntimeException e) {count = BigDecimal.ZERO;}
        
        return (count.compareTo(BigDecimal.ZERO)==0 ? false : true);
    }
    
    public boolean saveData(Marketing data) {
        return service.saveData(data);
    }
    
    public boolean deleteData(Marketing data) {
        return service.deleteData(data);
    }
}
